package com.example.dllo.my36kr.message.enter;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.main.MainActivity;
import com.example.dllo.my36kr.tools.BaseAty;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

/**
 * Created by dllo on 16/8/27.
 */
public class SetAty extends BaseAty implements View.OnClickListener {

    private BmobUser user;
    private String phone ;
    private String password ;
    private EditText phoneEt;
    private EditText passwordEt;

    @Override
    protected int setLayout() {
        return R.layout.act_set;
    }

    @Override
    protected void initView() {
        user = new BmobUser();
//        Button backBnt = bindView(R.id.ib_act_set_back);
//        backBnt.setOnClickListener(this);
        phoneEt = bindView(R.id.et_act_set_phone);
        passwordEt = bindView(R.id.et_act_set_password);

        Button completeBnt = bindView(R.id.bnt_act_set_complete);
        completeBnt.setOnClickListener(this);




    }

    @Override
    protected void initData() {


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
//            case R.id.ib_act_set_back:
//                finish();
//                break;
            case R.id.bnt_act_set_complete:
                phone = phoneEt.getText().toString();
                password = passwordEt.getText().toString();
                user.setUsername(phone);
                user.setPassword(password);
                user.signUp(new SaveListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {
                        if (e == null){
                            startActivity(new Intent(SetAty.this,EnterAty.class));
                            Toast.makeText(SetAty.this, "注册成功", Toast.LENGTH_SHORT).show();
                        }else {
                            Toast.makeText(SetAty.this, "注册失败", Toast.LENGTH_SHORT).show();
                        }
                    }
                });




                break;
        }
    }
}
